<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require dirname(__FILE__).'/pc_controller.php';

class Zmconfig extends PC_controller {

	protected $_configs = array();
	protected $_config_view = 'config';

	public function __construct(){
		parent::__construct();
		$this->load->model('Configmodel','m_config');
	}

	public function index(){
		$data = parent::index();

		$this->load->database();
		$assist = array();
		if(!empty($this->_configs)) {
			$assist['where_in']['config_name'] = $this->_configs;
		}
		$data['attr']['config_list'] = $this->m_config->outputConfigList4js($assist);
		$this->db->close();
		
		$this->load->view('admin/'.$this->_config_view,$data);
	}

	public function saveConfig(){
		$info = $this->input->post();

		$this->load->database();
		$insert_arr = array();
		foreach ($info as $key => $value) {
			if(!in_array($key, $this->_configs)) continue;
			$row = array(
				'user_id' => $this->m_app->getCurrentUserId(),
				'config_name' => $key,
				'config_value' => $value,
			);
			$row['config_id'] = $this->m_config->editConfig($row);

			$insert_arr[] = $row;
		}
		$this->m_config->createConfigHistoryBatch($insert_arr);
		$this->db->close();

		$this->response->setSuccess();
		$this->response->setDetail($this->lang->line('success_update'));
		$this->response->responseExit();
	}
}
/* End of file config.php */
/* Location: ./application/controllers/config.php */